package com.qipay.baas.mapper;

import com.qipay.baas.model.CpAccount;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CpAccountMapper {
    @Delete({
        "delete from cp_account",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long cpId);

    @Insert({
        "insert into cp_account (cp_id, balance, ",
        "balance_available, balance_advance, ",
        "balance_disabled, balance_advance_widthdraw)",
        "values (#{cpId,jdbcType=BIGINT}, #{balance,jdbcType=BIGINT}, ",
        "#{balanceAvailable,jdbcType=BIGINT}, #{balanceAdvance,jdbcType=BIGINT}, ",
        "#{balanceDisabled,jdbcType=BIGINT}, #{balanceAdvanceWidthdraw,jdbcType=BIGINT})"
    })
    int insert(CpAccount record);

    @InsertProvider(type=CpAccountSqlProvider.class, method="insertSelective")
    int insertSelective(CpAccount record);

    @Select({
        "select",
        "cp_id, balance, balance_available, balance_advance, balance_disabled, balance_advance_widthdraw",
        "from cp_account",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="balance", property="balance", jdbcType=JdbcType.BIGINT),
        @Result(column="balance_available", property="balanceAvailable", jdbcType=JdbcType.BIGINT),
        @Result(column="balance_advance", property="balanceAdvance", jdbcType=JdbcType.BIGINT),
        @Result(column="balance_disabled", property="balanceDisabled", jdbcType=JdbcType.BIGINT),
        @Result(column="balance_advance_widthdraw", property="balanceAdvanceWidthdraw", jdbcType=JdbcType.BIGINT)
    })
    CpAccount selectByPrimaryKey(Long cpId);

    @UpdateProvider(type=CpAccountSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CpAccount record);

    @Update({
        "update cp_account",
        "set balance = #{balance,jdbcType=BIGINT},",
          "balance_available = #{balanceAvailable,jdbcType=BIGINT},",
          "balance_advance = #{balanceAdvance,jdbcType=BIGINT},",
          "balance_disabled = #{balanceDisabled,jdbcType=BIGINT},",
          "balance_advance_widthdraw = #{balanceAdvanceWidthdraw,jdbcType=BIGINT}",
        "where cp_id = #{cpId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CpAccount record);
}